package com.company.wechatpush.entity;

import lombok.Data;

/**
 * @author Real
 * @since 2022-09-02 11:29 PM
 */
@Data
public class Solar {
    private static final Integer OCTOBER = 10;

    public Integer solarYear;
    public Integer solarMonth;
    public Integer solarDay;

    /**
     * 转成String类型的日期
     *
     * @return "yyyy-MM-dd"
     */
    public String getStringDate() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(this.solarYear);
        stringBuilder.append("-");
        if (this.solarMonth < OCTOBER) {
            stringBuilder.append(0);
        }
        stringBuilder.append(this.solarMonth);
        stringBuilder.append("-");
        if (this.solarDay < OCTOBER) {
            stringBuilder.append(0);
        }
        stringBuilder.append(this.solarDay);
        return stringBuilder.toString();
    }

    public void parseDate(String birthday) {
        String[] split = birthday.split("-");
        this.solarYear = Integer.parseInt(split[0]);
        this.solarMonth = Integer.parseInt(split[1]);
        this.solarDay = Integer.parseInt(split[2]);
    }

    @Override
    public String toString() {
        return solarYear + "年" + solarMonth + "月" + solarDay + "日";
    }
}
